package com.xiaolin.spring.xml;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @ClassName StaticFactoryInjectTest
 * @Description TODO
 * @Detail 静态工厂方法注入
 * @Author MyPC
 * @Date 2020/10/27
 * @Version 1.0
 */
public class StaticFactoryInjectTest2 {
    private Hello hello;
    private Integer i;

    //构造器私有
    private StaticFactoryInjectTest2(Hello hello,Integer i){
        this.hello=hello;
        this.i=i;
    }

    /**
     * 该方法同样是单例的
     * @param hello
     * @param i
     * @return
     */
    public static StaticFactoryInjectTest2 getInstance(Hello hello,Integer i){
        return new StaticFactoryInjectTest2(hello, i);
    }

    public static void main(String[] args) {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("static-factory.xml");
        StaticFactoryInjectTest2 s1 = applicationContext.getBean("static2", StaticFactoryInjectTest2.class);
        StaticFactoryInjectTest2 s2 = applicationContext.getBean("static2", StaticFactoryInjectTest2.class);
        System.out.println(s1);
        System.out.println(s1.hello);
        System.out.println(s2);
        System.out.println(s2.hello);
    }
}

class Hello{

}
